<template>
  <div class='container'>
    <el-card class="box-card">
      <!-- 筛选区域 -->
      <questions-filter ref="choiceFilter" @search="loadQuestionsChioceList($event)"/>
      <!-- 筛选区域/ -->

      <!-- 选项卡 -->
       <el-tabs v-model="activeName" type="card" @tab-click="onClickTab">
        <!-- 提示 -->
        <el-alert
          :title="'数据一共 '+ total +' 条'"
          type="info"
          show-icon
          :closable="false"
          style="margin-bottom:20px;"
          >
        </el-alert>
        <!-- 提示/ -->
        <el-tab-pane label="全部" name="first">
          <chioce-table
          :list="questionsChoiceList"
          @check-success="loadQuestionsChioceList"
          @pub-success="loadQuestionsChioceList"
          @delete-success="loadQuestionsChioceList"
          />
        </el-tab-pane>
        <el-tab-pane label="待审核" name="second">
          <chioce-table
          :list="questionsChoiceList"
          @check-success="loadQuestionsChioceList"
          @pub-success="loadQuestionsChioceList"
          @delete-success="loadQuestionsChioceList"
          />
        </el-tab-pane>
        <el-tab-pane label="已审核" name="third">
          <chioce-table
          :list="questionsChoiceList"
          @check-success="loadQuestionsChioceList"
          @pub-success="loadQuestionsChioceList"
          @delete-success="loadQuestionsChioceList"
          />
        </el-tab-pane>
        <el-tab-pane label="已拒绝" name="fourth">
          <chioce-table
          :list="questionsChoiceList"
          @check-success="loadQuestionsChioceList"
          @pub-success="loadQuestionsChioceList"
          @delete-success="loadQuestionsChioceList"
          />
        </el-tab-pane>
      </el-tabs>
      <!-- 选项卡/ -->

      <!-- 分页 -->
      <el-row>
        <el-col :span="6" :offset="18" style="margin-top:20px;">
          <page-tool
          :paginationPage="page"
          :paginationPagesize="pagesize"
          :total="total"
          @pageChange="onPageChange"
          @pageSizeChange="onPageSizeChange"
          />
        </el-col>
      </el-row>
      <!-- 分页/ -->

    </el-card>
  </div>
</template>

<script>
import questionsFilter from '../components/questions-filter.vue'
import PageTool from '../../module-dashboard/components/pageTool.vue'
import { choice as getQuestionsChioceList } from '@/api/hmmm/questions.js'
import ChioceTable from '../components/chioce-table.vue'

export default {
  name: 'questions-choice',
  components: { questionsFilter, PageTool, ChioceTable },
  data () {
    return {
      activeName: 'first',
      page: 1,
      pagesize: 5,
      total: 0,
      chkState: null,
      questionsChoiceList: []
    }
  },
  created () {
    this.loadQuestionsChioceList()
  },
  methods: {
    // 加载精选题库列表
    async loadQuestionsChioceList (queryData) {
      const { data } = await getQuestionsChioceList({
        page: this.page,
        pagesize: this.pagesize,
        chkState: this.chkState,
        ...queryData
      })
      this.questionsChoiceList = data.items
      this.total = data.counts
    },

    // 分页页码变化
    onPageChange (val) {
      this.page = val
      const queryData = this.$refs.choiceFilter.form
      this.loadQuestionsChioceList(queryData)
    },

    // 分页数量变化
    onPageSizeChange (val) {
      this.pagesize = val
      const queryData = this.$refs.choiceFilter.form
      this.loadQuestionsChioceList(queryData)
    },

    // 点击tabs栏
    onClickTab (tab) {
      if (tab.index === '0') {
        this.chkState = null
      } else {
        this.chkState = tab.index - 1
      }
      const queryData = this.$refs.choiceFilter.form
      this.loadQuestionsChioceList(queryData)
    },

    // 表头高亮
    tableHeaderStyle ({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background:#F5F7FA;color:#1f2d3d'
      } else {
        return ''
      }
    }

  }
}
</script>

<style scoped lang='less'>
.box-card {
  margin: 20px;
  /deep/.el-table th.el-table__cell>.cell{
  color: #909399;
  }
}
</style>
